<?php
class Default_AuthController extends Zend_Controller_Action
{
    public function init()
    {
        $this->_helper->layout->setLayout('login');
    }

    public function preDispatch()
    {
/*         if (Zend_Auth::getInstance()->hasIdentity()) {
                $this->_helper->redirector('index', 'index', 'admin');
         }*/
    }

    public function indexAction()
    {
        if (Zend_Auth::getInstance()->hasIdentity()) {
            $this->_helper->redirector('index', 'index', 'admin');
        }

        if($this->_request->isPost()) {
            $login      = $this->_request->getPost('login');
            $password   = $this->_request->getPost('password');

            $userDbMapper = new Default_Model_DbMapper_Users();
            $isLogin = $userDbMapper->login($login, $password);
            if($isLogin) {
                $this->redirect('/admin/');
            } else {
                $this->view->message = 'Неверно введенные данные!';
            }
        }
    }

    public function logoutAction()
    {
        Zend_Auth::getInstance()->clearIdentity();
        $this->_helper->redirector('index', 'index');
    }
}
?>